当前位置:flash课件吧→FLASH8.0教程→ flash cs3视频教程 flashcs3教程 flash cs3教程下载 flashcs3视频教程 flash cs3 pro教程 flash cs3教程网 flash cs3 实例教程 flashcs3教程下载 flash cs3教程 pdf flash cs3按钮教程

我站原创视频教程,网上视频教程学校,仅需要一个耳机+远程即可完成所有教学任务。

题 目:flash+asp+xml留言本教程

 

在下载到本地或者上传到空间上之前,请到后台修改参数设置里面的地址,然后进行测试!

如果你的机器或者服务器不支持FSO,请手动修改URL.XML文件里面的地址!

ASP主要部分:

page.ASP (传给Flash第n页的n条纪录)

 

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<% show_page = 9 '每页显示的纪录
db = "data/data.mdb" '数据库存放目录
'-连接数据库
set conn=server.createobject("adodb.connection")
conn.open "driver={microsoft Access driver (*.mdb)};dbq="&server.mappath(db)
'-----------------------------------------------------------------------
'用途:将UTF-8编码汉字转为GB2312码,兼容英文和数字!
function encodestr(str)
dim i
str=trim(str)
str=replace(str,"'","""")
str=replace(str,vbCrLf&vbCrlf,"</p><p>")
encodestr=replace(str,vbCrLf,"<br>")
end function
'用途:将UTF-8编码汉字转为GB2312码,兼容英文和数字!
Function uni(Chinese)
For j = 1 to Len (Chinese)
a=Mid(Chinese, j, 1)
uni= uni & "&#x" & Hex(Ascw(a)) & ";"
next
End Function %>
<%
'如果Flash传过来变量
if request("action")="showpage" then
'打开纪录
sql="select * from gbook order by id desc"
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,1,1
'---------------分页 开始
if not rs.eof then
'如果有记录
rs.PageSize = show_page
total=rs.RecordCount '共多少条记录
maxpage=rs.PageCount '共分几页
page=request("page") '当前页
if Not IsNumeric(page) or page="" then
page=1
else
page=cint(page)
end if
if page<1 then
page=1
elseif page>maxpage then
page=maxpage
end if
rs.AbsolutePage=Page
else
'如果没记录
total=0
maxpage=0
page=0
out=""
wujilu="1"
'把wujilu变量传给Flash,让flash知道没有记录然后做出相应的动作
'输出XML文件格式
Response.Write "<?XML version='1.0' encoding='utf-8'?>"
Response.Write "<gbook total='"&total&"' maxpage='"&maxpage&"' page='"&page&"' wujilu='"&wujilu&"'></gbook>"
Session.CodePage="936"
end if
'---------------分页 结束

'---------------打开 PageSize 条记录 开始
if not rs.eof then
'如果有记录
for i=1 to rs.PageSize
page_id=rs("id")
page_name=uni(rs("name"))
if len(rs("title")) > 19 then '截取字符
page_title=left(rs("title"),19)&".."'截取字符
else
page_title=rs("title")
end if
page_title=uni(page_title)
page_date=rs("date")
out=out&"<info page_id='"&page_id&"' page_name='"&page_name&"' page_title='"&page_title&"' page_date='"&page_date&"' />"
rs.movenext
if rs.EOF then
i=i+1
Exit For
end if
next
end if
'---------------打开 PageSize 条记录 结束
rs.close
set rs=nothing
conn.close
set conn=nothing'释放资源
'输出分页信息,XML格式
Response.Write "<?XML version='1.0' encoding='utf-8'?>"
Response.Write "<gbook total='"&total&"' maxpage='"&maxpage&"' page='"&page&"'>"&out&"</gbook>"
Session.CodePage="936"
end if
%>

 

show.ASP(传给Flash单条纪录的信息)

 

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
show_page = 9 '每页显示的纪录
db = "data/data.mdb" '数据库存放目录
set conn=server.createobject("adodb.connection")
conn.open "driver={microsoft Access driver (*.mdb)};dbq="&server.mappath(db)
'-----------------------------------------------------------------------
'用途:将UTF-8编码汉字转为GB2312码,兼容英文和数字!
function encodestr(str)
dim i
str=trim(str)
str=replace(str,"'","""")
str=replace(str,vbCrLf&vbCrlf,"</p><p>")
encodestr=replace(str,vbCrLf,"<br>")
end function
Function uni(Chinese)
For j = 1 to Len (Chinese)
a=Mid(Chinese, j, 1)
uni= uni & "&#x" & Hex(Ascw(a)) & ";"
next
End Function
'------------------------------------------------------------
%>
<%
if request("action")="show" then
'打开纪录为Flash传过来的第show_id条信息
sql="select * from gbook where id="&request("show_id")
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,1,1
'uni参数,就是把gb编码转换成utf-8编码,要不然Flash会乱码
show_name=uni(rs("name"))
show_id=uni(rs("id"))
show_title=uni(rs("title"))
if rs("email")<>"" then
show_email=uni(rs("email"))
end if
if rs("qq")<>"" then
show_qq=uni(rs("qq"))
end if
show_content=uni(rs("content"))
show_date=uni(rs("date"))
out=out&"<info show_name='"&show_name&"' show_id='"&show_id&"' show_title='"&show_title&"' show_email='"&show_email&"' show_qq='"&show_qq&"' show_content='"&show_content&"' show_date='"&show_date&"' />"
rs.close
set rs=nothing
conn.close
set conn=nothing
'输出XML格式
Response.Write "<?XML version='1.0' encoding='utf-8'?>"
Response.Write "<gbook>"&out&"</gbook>"
end if
%>

 

add.ASP(Flash传给asp增加纪录)

 

<%
show_page = 9 '每页显示的纪录
db = "data/data.mdb" '数据库存放目录
set conn=server.createobject("adodb.connection")
conn.open "driver={microsoft Access driver (*.mdb)};dbq="&server.mappath(db)
'-----------------------------------------------------------------------
'用途:将UTF-8编码汉字转为GB2312码,兼容英文和数字!
function encodestr(str)
dim i
str=trim(str)
str=replace(str,"'","""")
str=replace(str,vbCrLf&vbCrlf,"</p><p>")
encodestr=replace(str,vbCrLf,"<br>")
end function
Function uni(Chinese)
For j = 1 to Len (Chinese)
a=Mid(Chinese, j, 1)
uni= uni & "&#x" & Hex(Ascw(a)) & ";"
next
End Function
'------------------------------------------------------------
%>
<%
Session.CodePage="65001"
if encodestr(request("action"))="add" then'如果Flash传过来的变量是add
if encodestr(request("w_name"))="" then'如果w_name等于空
cuowu="n"
response.write"&addok="+cuowu '
elseif encodestr(request("w_title"))="" then '如果标题空
cuowu="t"
response.write"&addok="+cuowu
elseif encodestr(request("w_content"))="" then'如果留言内容空
cuowu="c"
response.write"&addok="+cuowu
end if
if cuowu="" then '如果姓名,标题,留言内容不为空
sql="select * from gbook "
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,3,3
rs.addnew '增加纪录
rs("name")=encodestr(request("w_name"))
rs("title")=encodestr(request("w_title"))
if encodestr(request("w_email"))="" then
rs("email")=null
else
rs("email")=encodestr(request("w_email"))
end if
if encodestr(request("w_qq"))="" then
rs("qq")=null
else
rs("qq")=encodestr(request("w_qq"))
end if
rs("content")=encodestr(request("w_content"))
rs("date")=date()
rs.update
rs.close
set rs=nothing
conn.close
set conn=nothing
response.write"&addok=ok" '返回给Flash 留言成功
end if
end if
Session.CodePage="936"
%>

 

 

 

Flash部分:

留言列表

 

function showPage()//定义函数
{
function titlemenu()
{
gbtitle.attachMovie("title_mc", "title_mc" + i, i);//循环增加MC
gbtitle["title_mc" + i]._y = 30 * i;//MC的位置
gbtitle["title_mc" + i].page_id = gb[i].attributes.page_id;//title_mc里面的动态文本显示ASP传来的变量
page_id=gb[i].attributes.page_id;
gbtitle["title_mc" + i].page_title = gb[i].attributes.page_title;
gbtitle["title_mc" + i].page_date = gb[i].attributes.page_date;
gbtitle["title_mc" + i].page_name = gb[i].attributes.page_name;
i++;
if (i >= nTotal)//如果纪录大于每页显示的纪录
{
clearInterval(nInterval);
} // end if
} // End function
total= pageXML.firstChild.attributes.total;
maxpage = pageXML.firstChild.attributes.maxpage;
page = pageXML.firstChild.attributes.page;
tPage = "第 " + page + " / " + maxpage + " 页 共 " + total + " 条留言";
gb = pageXML.firstChild.childNodes;
nTotal = gb.length;//共几个节点-共几条记录
var nInterval = setInterval(titlemenu, 50);//延迟加载
this.createEmptyMovieClip("gbtitle", 1);//创建空的mc
gbtitle._x = 10;
gbtitle._y = 70;
var i = 0;
} // End function
stop();
pageXML = new XML();//创建对象
pageXML.ignoreWhite = true;//忽略空格
pageXML.load(gbookurl+"page.ASP?action=showpage&page="+page + "&temp=" + Math.random() * Number(getTimer()));
pageXML.onLoad = function (success)
{
if (success)//如果读取成功
{
showPage(1);
//如果加载成功
//xiaoxi = "正在加载数据,请等待...";
//_root.xiaoxikuang.gotoAndPlay("wu");
//_root.jindutiao.gotoAndPlay("wu");
//gotoAndPlay(76);
}
else
{
gotoAndPlay("error");
//如果加载失败
_root.xiaoxikuang.xiaoxi = "无法连接到数据库,请检测网络连接";
} // end if
};// end function

 

读取单条纪录

gbtitle.removeMovieClip();//卸载留言列表
_global.zhen="read";
function Page(index)
{
//把ASP传来的变量传给动态文本
show_id = "ID:"+read[index].attributes.show_id;
show_name = "留言者:"+read[index].attributes.show_name;
show_title = "标题:"+read[index].attributes.show_title;
show_qq = "QQ:"+read[index].attributes.show_qq;
show_email = "E-mail:"+read[index].attributes.show_email;
show_content = read[index].attributes.show_content;
show_date = "发表时间:"+read[index].attributes.show_date;
} // End function
showXML = new XML();
showXML.ignoreWhite = true;
showXML.load(gbookurl+"show.ASP?action=show&show_id=" + go_id + "&temp=" + Math.random() * Number(getTimer()));
showXML.onLoad = function (success)
{
if (success)
{
//如果加载成功
_root.xiaoxikuang.xiaoxi = "正在加载数据,请等待...";
read = showXML.firstChild.childNodes;
Total = read.length;
Page(0);
gotoAndPlay(79);
}
else
{
gotoAndPlay("error");
//如果加载失败
_root.xiaoxikuang.xiaoxi = "无法连接到数据库,请检测网络连接";
} // end if
};// end function

写纪录

 

function sendData()
{
//把动态文本里的内容传给send_var
send_var.w_name = _root.w_name;
send_var.w_qq = _root.w_qq;
send_var.w_email = _root.w_email;
send_var.w_title = _root.w_title;
send_var.w_content = _root.w_content;
send_var.sendAndLoad(gbookurl+"add.ASP?action=add", load_var, "post");
} // End of the function

send_var = new LoadVars();
load_var = new LoadVars();
fabiao.onRelease = sendData;
load_var.onLoad = function ()
{

if (this.addok=="ok")
{
_root.xiaoxikuang.xiaoxi = "留言成功!";
gotoAndPlay("wok");
}
if (this.addok=="n")
{
_root.xiaoxikuang.xiaoxi = "姓名不能为空!";
gotoAndPlay("werror");
}
if (this.addok=="t")
{
_root.xiaoxikuang.xiaoxi = "标题不能为空!";
gotoAndPlay("werror");
}
if (this.addok=="c")
{
_root.xiaoxikuang.xiaoxi = "留言内容不能为空!";
gotoAndPlay("werror");
}

};//end load_var fun
chongzhi.onRelease = function() //重置按钮
{
_root.w_name = "";
_root.w_qq = "";
_root.w_email = "";
_root.w_title = "";
_root.w_content = "";
}
stop();

主要用到的代码就这些,还可以把后台管理功能加在Flash里面,但是因为我正在工作,没有时间,所以就做了一个简单的留言本!

 

 

 

省级FLASH课件制作培训请加我站管理QQ444860709 培训QQ专业群67042004。

FLASH8.0教程→ flash cs3视频教程 flashcs3教程 flash cs3教程下载 flashcs3视频教程 flash cs3 pro教程 flash cs3教程网 flash cs3 实例教程 flashcs3教程下载 flash cs3教程 pdf flash cs3按钮教程

期刊论文服务

合作期刊
学报期刊
 
获奖证书办理
本站已改版成新站 课件115学培吧http://www.kj115.com
在线咨询台